package com.google.coffeeshop.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "execution_order_line")
public class OrderLineDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "order_id", nullable = false)
	private OrderDTO order;
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "product_id", nullable = false)
	private ProductDTO product;
	@Column(name = "quantity", nullable = false)
	private long quantity;
	@Column(name = "unit_price", nullable = false)
	private long priceOfUnit;

	@Transient
	private boolean served = false;
	
	@Override
	public String toString() {
		String orderId = "null";
		if (null != order && null != order.getId()) {
			orderId = order.getId().toString();
		}
		return String.format("id=%d, orderId=%s", id, orderId);
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public OrderDTO getOrder() {
		return order;
	}
	public void setOrder(OrderDTO order) {
		this.order = order;
	}
	public ProductDTO getProduct() {
		return product;
	}
	public void setProduct(ProductDTO product) {
		this.product = product;
	}
	public long getQuantity() {
		return quantity;
	}
	public void setQuantity(long quantity) {
		this.quantity = quantity;
	}
	public long getPriceOfUnit() {
		return priceOfUnit;
	}
	public void setPriceOfUnit(long price) {
		this.priceOfUnit = price;
	}
	public boolean isServed() {
		return served;
	}
	public void setServed(boolean served) {
		this.served = served;
	}
}
